package com.vrv.common;

import android.content.Context;
import android.util.Log;

import com.vrv.common.utils.SharedPreferenceHelper;

/**
 * 服务器IP、port保存获取等
 *
 * @author zxb
 */
public class UrlPrefix {

    private static final boolean DEBUG = true;
    private static final String TAG = UrlPrefix.class.getSimpleName();

    public Context mContext;

    public UrlPrefix(Context context) {
        this.mContext = context;
    }

    public static Context sContext;

    public static void init(Context ctx) {
        sContext = ctx;
    }

    /** 协议头 */
    public static final String PREFIX = "http://";
    /** 项目名 */
    public static final String PROJECT = "EDPDMServer";
    /** 路径分隔符 */
    public static final String SPLIT_PORT = ":";

    public static final String SPLIT = "/";

    public static String getUrlPrefix() {
        if (DEBUG)
            Log.v(TAG, "public String getUrlPrefix()");

        SharedPreferenceHelper sp = new SharedPreferenceHelper(sContext, Constants.SERVER_INFO_FILENAME);
        String ipValue = sp.getValue(Constants.SERVER_IP_KEY);
        String portValue = sp.getValue(Constants.SERVER_PORT_KEY);

        if (null == ipValue || null == portValue) {
            return null;
        }

        String url = PREFIX + ipValue + SPLIT_PORT + portValue + SPLIT + PROJECT;
        if (DEBUG)
            Log.v(TAG, url);
        return url;
    }
}
